<template>
	<view class="page">
		<!-- <u-navbar bgColor='#4871C0' :titleStyle="{ color: '#FFF'}" title="草稿" leftIconColor="#FFF"
			@rightClick="rightClick" :autoBack="true"  >
		</u-navbar> -->
		<view class="list manage">
			<view class="list-title">
				内部管理
			</view>
			<view class="option">
				<view class="option-item"  @tap.stop="gotoSchoolEvent()">
					<view class="item-img">

					</view>
					<view class="item-text">
						学校大事件
					</view>
				</view>
				<view class="option-item"  @tap.stop="toArchives()">
					<view class="item-img">

					</view>
					<view class="item-text">
						教师档案
					</view>
				</view>
			<view class="option-item"  @tap.stop="toSalary()">
				<view class="item-img">

				</view>
				<view class="item-text">
					工资
				</view>
			</view>
        <view class="option-item" @click="fuBtn(item)">
          <text>预览页面 单独方法</text>
        </view>
        <view class="option-item file-box u-flex" @click="handleDownload()">
          <u-icon name="attach" color="#4871C0" size="24"></u-icon>
          <text>预览</text>
        </view>
        <view class="option-item" @click="gohuiyi()">
          <text>跳转会议</text>
        </view>
        <view class="option-item" @click="gozhoujihua()">
          <text>跳转周计划</text>
        </view>
        <view class="option-item" @click="gozhoujihua1()">
          <text>跳转周计划333</text>
        </view>
			</view>
		</view>

	</view>
</template>

<script>
import {
	getWxSign
} from '@/api/userApi.js'
import {
	openFileInit
} from '@/api/meetApi.js'
	export default {
		data() {
			return {
        fileList1:[],
        files: null,
        fileName: null,
        item:{
          url: this.$httpApi+"/uploads/20220903/acb26a14092d37e167f2761454f848d9.doc",
          name: "测试222.doc",
          size: "11264" // 需要预览文件的字节大小(必填)
        }
			}
		},
		onLoad() {

		},
		methods: {
		  gohuiyi(){
			uni.navigateTo({
			  url: '/pages/tabbar-1-detial/meetingDetails/meetingDetails?id=204&token=457f6514-8d7a-4f85-8784-81080755fdd9'
			});
		  },
      gozhoujihua(){
        uni.navigateTo({
          url: '/pages/feedback/list?id=174&token=457f6514-8d7a-4f85-8784-81080755fdd9'
        });
      },
      gozhoujihua1(){
        uni.navigateTo({
          url: '/pages/feedback/feedback?meet_id=214&token=457f6514-8d7a-4f85-8784-81080755fdd9'
        });
      },
			gotoSchoolEvent(){
				uni.navigateTo({
					url: '/pages/tabbar-5-detial/schoolEvent/schoolEvent'
				});
			},
			toArchives(){
			uni.navigateTo({
				url: "/pages/archives/index/index"
			});
		},
		toSalary(){
			uni.navigateTo({
				url: "/pages/salary/index"
			});
		},
      fuBtn() {
			 let item = {
         fullurl: this.$httpApi+"/uploads/20220903/acb26a14092d37e167f2761454f848d9.doc",
         filename: "测试222.doc",
         filesize: "11264" // 需要预览文件的字节大小(必填)
        };
        console.log("=========itemss",item)
         uni.navigateTo({
          url: '/pages/yulan/yulan?fileurl=' + item.fullurl+'&typeName='+item.filename+'&filesize='+item.filesize
        });
      },
      // 点击附件预览
      handleDownload(item) {
			  //this.$store.dispatch('yulan',item)
         getWxSign({
          url: encodeURIComponent(window.location.href.split('#')[0])// 注意：location.href
        }).then(res => {
           console.log(window.jWeixin, "window.jWeixin")
           console.log(window.wx, "window.wx")
           const u = navigator.userAgent,
             isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
             isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
           if(isAndroid){
             window.wx = window.jWeixin
           }
           var wx = window.wx ? window.wx : window.jWeixin;
           console.log(wx, "wx")
          // 步骤二：通过config接口注入权限验证配置
           wx.config({
            beta: true, // 必须这么写，否则wx.invoke调用形式的jsapi会有问题
            debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来
            appId: res.data.qiye.corpid, // 必填，企业微信的corpID。公司的唯一标识‘ww20745c5e79cfa434’
            timestamp: res.data.qiye.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.data.qiye.nonceStr, // 必填，生成签名的随机串，这里用的是自定义方法
            signature: res.data.qiye.signature, // 必填，签名，见附录-JS-SDK使用权限签名算法 https://work.weixin.qq.com/api/doc/90000/90136/90506
            jsApiList: res.data.qiye.jsApiList, // 必填，需要使用的JS接口列表，凡是要调用的接口都需要传进来。所有JS接口列表见附录2
            success: function(res) {
              // 回调
              console.log("===========222成功")

            },
			fail:function(res){
				  console.log("===========111失败")
			},
          });
           // 步骤三：通过ready接口处理成功验证。没有需要立即调用的api，可以不写
           wx.ready(function() {
			    console.log("4444")
             wx.agentConfig({
                 corpid: res.data.app.corpid, // 必填，企业微信的corpid，必须与当前登录的企业一致
                 agentid: res.data.app.agentid, // 必填，企业微信的应用id （e.g. 1000247）
                 timestamp:res.data.app.timestamp,  // 必填，生成签名的时间戳
                 nonceStr:res.data.app.nonceStr, // 必填，生成签名的随机串
                 signature: res.data.app.signature, // 必填，签名，见附录-JS-SDK使用权限签名算法
                 jsApiList: res.data.app.jsApiList , //必填，传入需要使用的接口名称
                 success: function(res) {
                  //  wx.previewFile({
                  //   url: this.$httpApi+"/uploads/20220903/acb26a14092d37e167f2761454f848d9.doc",
                  //   name: "测试222.doc",
                  //   size: "11264" // 需要预览文件的字节大小(必填)
                  // });
                   wx.previewImage({
                     current: "http://wework.qpic.cn/bizmail/73HciaQWhnd3GySe5rnfEHFkibsyoxxuCCJPZxYoKrYMalgh7NZztH6g/0",
                     urls:['http://wework.qpic.cn/bizmail/73HciaQWhnd3GySe5rnfEHFkibsyoxxuCCJPZxYoKrYMalgh7NZztH6g/0']
                   });
                 },
                 fail: function(res) {
                   console.log("======reslog",res)
                  alert('预览文件出错')
                   if(res.errMsg.indexOf('function not exist') > -1){
                     alert('版本过低请升级')
                   }
                 }
               });
             });
           // 步骤四：通过error接口处理失败验证
           wx.error(function(err) {
            console.log("333333")
             console.log("-======err",err)
           });
        });
      },
      // 新增文件
      async afterRead1(event) {
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        let lists = [].concat(event.file)
        let fileListLen = this.fileList1.length
        lists.map((item) => {
          this.fileList1.push({
            ...item
          })
        })
        for (let i = 0; i < lists.length; i++) {
          const result = await this.uploadFilePromise1(lists[i].url)
          this.files = result;
          this.fileName = this.files.filename,
              fileListLen++
        }
        console.log("========this.fileList1",this.fileList1, this.files )
      },
      uploadFilePromise1(url) {
        return new Promise((resolve, reject) => {
          let a = uni.uploadFile({
            url: HTTP_REQUEST_URL + '/api/common/upload', // 仅为示例，非真实的接口地址
            filePath: url,
            name: 'file',
            formData: {
              user: 'test'
            },
            success: (res) => {
              if(JSON.parse(res.data).code == 1){
                setTimeout(() => {
                  resolve(JSON.parse(res.data).data.files)
                }, 500)
              }
              else{
                uni.showToast({
                  title:JSON.parse(res.data).msg,
                  icon: 'none',
                  duration: 1000
                });
              }
            }
          });
        })
      },
      deletePic1() {
        this.fileList1.splice(event.index, 1)
        this.files = null;
        this.fileName = null;
      },
		}
	}
</script>

<style>
	.page{
		/* padding: 0 20rpx;	 */
		background-color: #f5f6f8;
		min-height: 100vh;
	}
	.list{
		background-color: #fff;
	}
	.list.manage{
		border-radius: 0 0 16rpx 16rpx;
	}
	.list .list-title{
		padding: 20rpx 0;
		border-bottom: 1px solid #eee;
		padding-left: 20rpx;
		color: #b0b0b0;
	}
	.option{
		display: flex;
		flex-wrap: wrap;
	}
	.option-item{
		width: 33.33%;
		display: flex;
		flex-direction: column;
		align-items: center;
		border: 1px solid #eee;
		border-top: none;
		box-sizing: border-box;
		padding: 50rpx 0;
	}
	.option-item:nth-child(3n + 1){
		border-left: none;
	}
	.option-item:nth-child(3n + 3){
		border-right: none;
	}
	.option-item:nth-child(3n + 2){
		border-right: none;
		border-left: none;
	}
	.item-img{
		width: 80rpx;
		height: 80rpx;
		background-color: #fcb204;
	}
	.item-text{
		margin-top: 20rpx;
	}
</style>
